package br.com.bluelogic.dao;

import br.com.bluelogic.bean.Usuario;
import java.util.List;
import org.hibernate.Session;

public class UsuarioDAO implements InterfaceCRUD {   
   
    public boolean salvar(Usuario user) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        session.save(user);
        tx.commit();
        session.close();
        return true;
    }

    public boolean atualizar(Usuario user) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        session.update(user);
        tx.commit();
        session.close();
        return true;
    }
    public boolean excluir(Usuario user) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        session.delete(user);
        tx.commit();
        session.close();
        return true;
    }

    public List listarUsuario() {
        Session session = (Session) HibernateUtil.getSessionFactory().openSession();
        List listaUsuarios = session.createQuery("from Usuario").list();
        return  listaUsuarios;
    }
    
}
